package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.Dynamic;
import com.systemic.pojo.Subject;
import com.systemic.pojo.SubjectFollower;
import com.systemic.service.SubjectService;
import com.systemic.vo.PageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: SubjectController
 * @Description: 话题
 * @Author:
 * @CreateTime: 2024-01-18 09:47
 * @Version:
 **/
@RestController
@RequestMapping("/subject")
public class SubjectController {

    @Resource
    private SubjectService subjectService;

    /**
     * 创建话题
     * @param subject
     * @return
     */
    @PostMapping("/create")
    public ResponseResult<String> create(@RequestBody Subject subject){
        int row = subjectService.create(subject);
        return row != 0 ? ResponseResult.success("创建话题成功！") : ResponseResult.failed("创建失败");
    }


    /**
     * 删除话题
     * @param ids
     * @return
     */
    @GetMapping("/deleteList/{ids}")
    public ResponseResult<String> deleteList(@PathVariable("ids") Integer[] ids){
        int row = subjectService.deleteList(ids);
        return row != 0 ? ResponseResult.success("删除话题成功！") : ResponseResult.failed("删除话题失败");
    }

    /**
     * 查询话题
     * @param sname
     * @return
     */
    @GetMapping("/select/{sname}")
    public ResponseResult<List<Subject>> select(@PathVariable("sname") String sname){
        List<Subject> subjectList = subjectService.selectByName(sname);
        return !subjectList.isEmpty() ? ResponseResult.success(subjectList) : ResponseResult.failed(null);
    }

    /**
     * 关注话题
     * @param subjectFollower
     * @return
     */
    @PostMapping("/follow")
    public ResponseResult<String> follow(@RequestBody SubjectFollower subjectFollower){
        int row = subjectService.follow(subjectFollower);
        return row != 0 ? ResponseResult.success("关注话题成功！") : ResponseResult.failed("关注话题失败");
    }

    /**
     * 取消关注话题
     * @param subjectFollower
     * @return
     */
    @PostMapping("/unfollow")
    public ResponseResult<String> unfollow(@RequestBody SubjectFollower subjectFollower){
        int row = subjectService.unfollow(subjectFollower);
        return row != 0 ? ResponseResult.success("关注话题成功！") : ResponseResult.failed("关注话题失败");
    }


    /**
     * 话题显示动态
     * @param pageVo
     * @return
     */
    @PostMapping("/dynamic")
    public ResponseResult<List<Dynamic>> dynamic(@RequestBody PageVo pageVo){
        List<Dynamic> dynamicList = subjectService.dynamic(pageVo);
        return !dynamicList.isEmpty() ? ResponseResult.success(dynamicList) : ResponseResult.failed(null);
    }




}
